﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TouchSocket.Core;
using TouchSocket.Sockets;

namespace ConsoleApp1
{
    public class TcpConnectedPlugin : ITcpConnectedPlugin
    {
        public bool DisposedValue { get; private set; } = false;

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!DisposedValue)
            {
                if (disposing)
                {
                    // 释放托管资源
                }

                // 释放非托管资源
                DisposedValue = true;
            }
        }

        public void Loaded(IPluginManager pluginManager)
        {
            Console.WriteLine("TcpConnected插件已加载");
        }

        public Task OnTcpConnected(ITcpSession client, ConnectedEventArgs e)
        {
            Console.WriteLine("已经连接到：" + ((ITcpClient)client).RemoteIPHost);
            return e.InvokeNext();
        }

        public void Unloaded(IPluginManager pluginManager)
        {
            Console.WriteLine("TcpConnected插件已卸载");
        }
    }
}
